<template>
    <div class="infoDetail">
        <div class="all">
            <image :src="imgPath('bg2.png')" class="inner-img"></image>
            <image :src="imgPath('bg1.png')" class="inner-img"></image>
        </div>
        <div class="header">
            <div class="backPage" @click="backPage">
                <image class="arrow_left" :src="imgPath('back.png')"></image>
                <text class="back col_fff medium">返回</text>
            </div>
            <text class="title col_fff regular">店铺详情</text>
            <image :src="imgPath('Shopping.png')" class="carImg" @click="pushToCar"></image>
        </div>
        <div class="allwrapCon">
            <scroller>
                <div class="itemCon">
                    <div class="item1">
                        <div class="info-left">
                            <div class="storeWrap">
                                <image :src="storeList.headPicture" class="storeImg"></image>
                            </div>
                            <div class="info-center">
                                <text class="storeName">{{storeList.name}}</text>
                                <div class="info-bottom">
                                    <div class="see">
                                        <image :src="imgPath('follow.png')" class="seeImg"></image>
                                        <text class="seeText">{{storeList.concernNumber ? storeList.concernNumber : 0}}</text>
                                    </div>
                                    <div class="see look">
                                        <image :src="imgPath('swimsuit.png')" class="seeImg"></image>
                                        <text class="seeText">{{storeList.goodsNumber ? storeList.goodsNumber : 0}}</text>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <text class="concernText" :class="[storeList.isCollection ? 'yellowColor': 'concernText']"
                              @click="keep">收藏
                        </text>
                    </div>
                    <div class="item">
                        <div class="list">
                            <text class="list-text prise">商品评价</text>
                            <div class="listImg">
                                <image v-for="i in 5" :key="i" :src="imgPath('xingxing.png')" class="pingjia"></image>
                            </div>
                        </div>
                        <div class="list">
                            <text class="list-text prise">服务评价</text>
                            <div class="listImg">
                                <image v-for="i in 5" :key="i" :src="imgPath('xingxing.png')" class="pingjia"></image>
                            </div>
                        </div>
                        <div class="list">
                            <text class="list-text prise">响应速度</text>
                            <div class="listImg">
                                <image v-for="i in 5" :key="i" :src="imgPath('xingxing.png')" class="pingjia"></image>
                            </div>
                        </div>
                    </div>
                    <div class="item">
                        <div class="list">
                            <text class="list-text">证照信息</text>
                            <image :src="imgPath('zhengjian.png')" class="zhengjian" @click="previewImage"></image>
                        </div>
                        <div class="list">
                            <text class="list-text">店铺二维码</text>
                            <image :src="imgPath('erweima.png')" class="zhengjian" @click="yulanImage"></image>
                        </div>
                    </div>
                    <div class="item">
                        <div class="list">
                            <text class="list-text">店铺简介</text>
                            <text class="list-text1" v-if="storeList.synopsis">{{storeList.synopsis}}</text>
                            <text class="list-text1" v-if="!storeList.synopsis">暂无简介</text>
                        </div>
                        <div class="list">
                            <text class="list-text">认证时间</text>
                            <text class="list-text1">{{storeList.authenticationDate}}</text>
                        </div>
                        <div class="list">
                            <text class="list-text">所在地区</text>
                            <text class="list-text1">{{provinceName}}{{cityName}}</text>
                        </div>
                        <div class="list">
                            <text class="list-text">联系人</text>
                            <text class="list-text1" v-if="storeList.contact">{{storeList.contact}}</text>
                            <text class="list-text1" v-if="!storeList.contact">暂无填写联系人</text>
                        </div>
                        <div class="list">
                            <text class="list-text">联系方式</text>
                            <text class="list-text1" v-if="storeList.telephone">{{storeList.telephone}}</text>
                            <text class="list-text1" v-if="!storeList.telephone">暂无填写联系方式</text>
                        </div>
                    </div>
                    <div class="item">
                        <text class="title1">商家详情介绍</text>
                        <text class="content" v-if="storeList.info">{{storeList.info}}</text>
                        <text class="content" v-if="!storeList.info">暂无介绍</text>
                    </div>
                </div>
                <Preview :show="previewShow" :src="storeList.licenceInfoUrl" @hidePreview="hidePreview"></Preview>
                <Preview :show="yulanShow" :src="storeList.paymentCodeUrl" @hidePreview="hideYulan"></Preview>
            </scroller>
        </div>
        <wxc-loading :show="loadingShow" :need-mask="needMask"></wxc-loading>
    </div>
</template>

<script>
import { infoDetail, myCollect, cancelCollect } from '@/api/store'
import {getProvince, getCity} from '@/api/order'
import Preview from '@/components/preview'
import { WxcLoading } from 'weex-ui'
const storage = weex.requireModule('storage')
const modal = weex.requireModule('modal')
export default {
  name: 'infoDetail',
  data () {
    return {
      storeList: {},
      userId: '',
      previewShow: false, // 预览弹窗隐藏
      yulanShow: false,
      shopsId: '',
      addressList: [],
      provinceName: '',
      cityName: '',
      shoucang: '',
      needMask: true, // 显示蒙版
      loadingShow: true // loading

    }
  },
  methods: {
    backPage () {
      this.$router.go(-1)
    },
    previewImage (e) { // 图片预览
      const view = e.target
      let url = ''
      if (weex.config.env.platform === 'Web') {
        url = view.getAttribute('src')
      } else {
        url = view.attr.src
      }
      this.imageSrc = url
      this.previewShow = true
    },
    hidePreview () { // 隐藏预览
      this.previewShow = false
    },
    yulanImage (e) {
      const view = e.target
      let url = ''
      if (weex.config.env.platform === 'Web') {
        url = view.getAttribute('src')
      } else {
        url = view.attr.src
      }
      this.imageSrc = url
      this.yulanShow = true
    },
    hideYulan () { // 隐藏预览
      this.yulanShow = false
    },
    // 点击进行收藏
    keep () {
      const that = this
      let params = {
        goodsId: '',
        shopId: that.$route.query.shopsId,
        type: 2
      }
      if (!that.storeList.isCollection) {
        that.$api.post(myCollect, params, function (res) {
          modal.toast({
            message: '收藏成功'
          })
          that.storeList.isCollection = true
        }, function () {}, true)
      } else {
        that.$api.post(cancelCollect, params, function (res) {
          modal.toast({
            message: '取消收藏'
          })
          that.storeList.isCollection = false
        }, function () {}, true)
      }
    },
    // 点击进入购物车
    pushToCar () {
      const that = this
      that.$router.push('/store/shoppingCar')
    }
  },
  mounted: function () {
    const that = this
    that.shopsId = that.$route.query.shopsId
    storage.getItem('userId', event => {
      if (event.result === 'success') {
        that.userId = event.data
        that.loadingShow = true
        let params = {}
        params.userId = that.userId ? that.userId : ''
        that.loadingShow = true
        that.$api.get(infoDetail + '/' + that.shopsId, params, function (res) {
          that.loadingShow = false
          that.storeList = res.data
          if (that.storeList.provinceId) {
            that.$api.get(getProvince + '/' + '0', {}, function (pro) {
              for (let i = 0; i < pro.data.length; i++) {
                if (that.storeList.provinceId === pro.data[i].id) {
                  that.provinceName = pro.data[i].name
                }
              }
            })
            that.$api.get(getCity + '/' + that.storeList.cityId, {}, function (res1) {
              that.cityName = res1.data.name
            })
          }
        }, function () {
          that.loadingShow = false
        })
      }
    })
  },
  components: {
    Preview,
    WxcLoading
  }
}
</script>

<style scoped>
.carImg{
    width:40px;
    height:40px;
}
.col_fff {
    color: #fff;
}
.regular {
    font-family: regular;
}
.medium {
    font-family: medium;
}
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    flex-wrap: wrap;
    flex-direction: row;
    height: 88px;
    justify-content: space-between;
    padding-left: 24px;
    padding-right: 24px;
    align-items: center;
}
.backPage {
    flex-direction: row;
    align-items: center;
    height: 88px;
}
.arrow_left {
    width: 24px;
    height: 40px;
    margin-right: 16px;
}
.back {
    font-size: 34px;
    line-height: 88px;
}
.title {
    width: 440px;
    text-align: center;
    font-size: 34px;
    font-weight: bold;
    line-height: 88px;
}
.all{
    width: 750px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}
.inner-img {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 750px;
    height:900px;
}
.mainCon{
    padding-bottom:100px;
    padding-right: 24px;
    padding-left: 24px;
    padding-top: 24px;
}
    .item{
        background-color: #fff;
        border-radius: 20px;
        padding-left: 24px;
        padding-right: 24px;
        padding-bottom: 24px;
        flex-direction: column;
        justify-content: space-between;
        margin-bottom: 24px;
        border-width:1px;
        border-style:solid;
        border-color:#ebebeb;
        padding-left: 24px;
        padding-top: 24px;
        padding-right: 24px;
    }
.item1{
    justify-content: space-between;
    flex-direction: row;
    background-color: #fff;
    border-radius: 20px;
    padding-left: 24px;
    padding-right: 24px;
    padding-bottom: 24px;
    margin-bottom: 24px;
    border-width:1px;
    border-style:solid;
    align-items: center;
    padding-top: 24px;
    border-color:#ebebeb;
}
.itemCon{
    padding-left: 24px;
    padding-right: 24px;
}
.info-left{
    flex-direction: row;
}
.storeWrap{
    width:140px;
    height:140px;
    background-color:#fff;
    flex-direction:row;
    align-items: center;
    border-radius: 10px;
    border-width: 1px;
    border-color: rgb(245,245,245);
    border-style: solid;
}
.storeImg{
    width:140px;
    height:140px;
}
.info-center{
    width:300px;
    flex-direction:row;
    flex-wrap:wrap;
    flex-direction:column;
    margin-left:15px;
}
.see{
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
.seeImg{
    width:42px;
    height:42px;
    margin-right: 14px;
}
.seeText{
    font-size:24px;
    color:rgb(134,134,134);
}
.look{
    margin-left: 70px;
}
.storeName{
    font-size:28px;
    font-weight: bold;
    color:rgb(70,70,70)
}
.info-bottom{
    flex-direction: row;
    margin-top:25px;
}
.info-right{
    flex-direction:row;
    align-items:center;
    justify-content: center;
}
.concernText{
    width: 120px;
    height: 50px;
    border-width: 1px;
    border-style: solid;
    border-color: rgb(70, 70, 70);
    color: rgb(70, 70, 70);
    text-align: center;
    line-height: 50px;
    font-size: 26px;
    border-radius: 10px;
}
.yellowColor {
    color:rgb(254,203,1);
    border-width: 1px;
    border-style: solid;
    border-color: rgb(254, 203, 1);
    text-align: center;
    line-height: 50px;
    font-size: 26px;
    border-radius: 10px;
}
    .list{
        flex-direction: row;
        margin-top: 24px;
    }
    .listImg{
        flex-direction: row;
    }
    .pingjia{
        width: 26px;
        height:26px;
        margin-right: 7px;
    }
    .list-text{
       width:145px;
        font-size:28px;
        color:rgb(70,70,70);
        font-weight:bold;
        margin-right: 10px;
    }
    .prise{
        font-size:24px;
        color:rgb(134,134,134);
        font-family: regular;
    }
    .list-text1{
        font-size: 26px;
        color: rgb(70,70,70);
        font-family: meduim;
    }
    .zhengjian{
        width:40px;
        height:40px;
    }
    .title1{
        font-size:28px;
        font-weight:bold;
        margin-top:24px;
    }
    .content{
        font-size:28px;
        color:rgb(70,70,70);
        font-family:regular;
        margin-top:15px;
    }
    .itemCon{
        margin-top: 88px;
    }
    .allwrapCon{
        position: fixed;
        top: 90px;
        bottom: 0;
        left: 0;
        right: 0;
    }
</style>
